/* =====================================================================
   COZY FIX-UP — STYLES
   Sections: 1) Reset & tokens  2) Viewport / scalable shell
   3) Top bar  4) Room / stage  5) Items  6) Bottom bar  7) Modals
   8) Shop  9) Inventory  10) Toast  11) Screen panel
   12) Rotation hint  13) Coin editor  14) Responsive
   ===================================================================== */

/* ---------- 1. RESET & DESIGN TOKENS -------------------------------- */
:root{
  --purple-950:#1c0f38;
  --purple-900:#2c1856;
  --purple-800:#3c2170;
  --purple-700:#4d2c8c;
  --purple-600:#6338ab;
  --purple-500:#8455c9;
  --lilac-200:#ece1fb;
  --cream:#fbf1da;
  --parchment:#f6e9c9;
  --parchment-dark:#ecd9a8;
  --coral:#f2765a;
  --coral-dark:#d85e42;
  --gold:#f3c14a;
  --gold-light:#ffe9a8;
  --gold-dark:#a8781f;
  --gold-edge:#8a611a;
  --green:#57b894;
  --red:#e0574f;
  --ink:#3a2a5c;
  --ink-strong:#2a1a4a;
  --muted:#8674a8;
  --radius-lg:22px;
  --radius-md:14px;
  --radius-sm:9px;
  --shadow-soft:0 12px 34px rgba(15,6,36,0.45);
  --shadow-pop:0 6px 16px rgba(20,8,44,0.35);
  --font-display:"Baloo 2", "Segoe UI", system-ui, sans-serif;
  --font-body:"Nunito", "Segoe UI", system-ui, sans-serif;
  font-size:16px;
}

*, *::before, *::after{ box-sizing:border-box; }
html, body{
  margin:0; padding:0; height:100%;
  font-family:var(--font-body);
  background:
    radial-gradient(ellipse 120% 70% at 50% -10%, #6a3fb0 0%, transparent 55%),
    linear-gradient(180deg, var(--purple-950) 0%, var(--purple-900) 45%, var(--purple-800) 100%);
  color:var(--ink);
  overflow:hidden;
  overscroll-behavior:none;
  -webkit-text-size-adjust:100%;
  -webkit-tap-highlight-color:transparent;
}
button{ font-family:inherit; cursor:pointer; touch-action:manipulation; user-select:none; -webkit-user-select:none; }
img{ user-select:none; -webkit-user-drag:none; }
.hidden{ display:none !important; }
.muted{ color:var(--muted); font-size:.9rem; }

/* generic buttons -------------------------------------------------- */
.btn{
  border:none; border-radius:999px; padding:.65rem 1.15rem;
  font-family:var(--font-display);
  font-weight:700; font-size:.92rem; letter-spacing:.01em;
  box-shadow:var(--shadow-pop);
  border:2px solid transparent;
  transition:transform .12s ease, box-shadow .12s ease, filter .12s ease;
  color:var(--ink-strong);
  background:linear-gradient(180deg,#fff8ea,var(--cream));
}
.btn:hover{ transform:translateY(-2px); filter:brightness(1.04); }
.btn:active{ transform:translateY(0px) scale(.98); }
.btn-primary{
  background:linear-gradient(180deg, var(--gold-light), var(--gold) 60%, var(--gold-dark));
  border-color:var(--gold-edge);
  color:#4a2f08;
  text-shadow:0 1px 0 rgba(255,255,255,.35);
}
.btn-ghost{ background:linear-gradient(180deg,#efe3ff,#ddc9fb); color:var(--purple-800); border-color:rgba(255,255,255,.4); }
.btn-danger{ background:linear-gradient(180deg,#ef7a72, var(--red)); color:#fff; }
.btn-block{ width:100%; display:block; margin-bottom:.5rem; text-align:center; }
.btn-round{
  border-radius:999px; padding:.8rem 1.3rem; font-size:1rem;
  display:flex; align-items:center; gap:.4rem;
}

/* ---------- 2. VIEWPORT / SCALABLE SHELL ----------------------------- */
/*
   The whole game is rendered inside a fixed 1280x952 canvas
   (#gameShell) which is scaled with a CSS transform to fit the
   browser window ("contain"): every element always stays fully
   visible, page itself never scrolls, and the shell keeps the
   game's original proportions. The available space excludes the
   browser's visible-viewport area and the env(safe-area-inset-*)
   safe zones (notches / rounded corners on phones).
*/
.game-viewport{
  position:fixed; inset:0;
  display:flex; align-items:center; justify-content:center;
  overflow:hidden;
  padding:
    env(safe-area-inset-top)
    env(safe-area-inset-right)
    env(safe-area-inset-bottom)
    env(safe-area-inset-left);
  background:
    radial-gradient(ellipse 120% 70% at 50% -10%, #6a3fb0 0%, transparent 55%),
    linear-gradient(180deg, var(--purple-950) 0%, var(--purple-900) 45%, var(--purple-800) 100%);
}
.game-shell{
  position:relative;
  width:1280px; height:952px;          /* design size — JS keeps this in sync */
  flex:0 0 auto;
  overflow:hidden;                      /* clip content instead of scrolling */
  transform:scale(0.001);               /* hidden until JS calculates the fit */
  transform-origin:center center;
  will-change:transform;
  transition:transform .12s ease;
}

/* ---------- 3. TOP BAR ------------------------------------------------ */
.topbar{
  position:absolute; top:0; left:0; right:0; height:64px; z-index:40;
  display:flex; align-items:center; gap:1rem; padding:0 1.1rem;
  background:linear-gradient(180deg, rgba(60,33,112,0.92), rgba(44,24,86,0.88));
  backdrop-filter:blur(10px);
  border-bottom:2px solid var(--gold);
  box-shadow:0 4px 14px rgba(0,0,0,.25);
}
.brand{ font-family:var(--font-display); font-weight:800; color:var(--gold-light); font-size:1.1rem; white-space:nowrap; text-shadow:0 2px 4px rgba(0,0,0,.4); }

.coin-pill{
  display:flex; align-items:center; gap:.4rem;
  background:linear-gradient(180deg,#fff5d8,#ffdb7a);
  border:2px solid var(--gold-dark); border-radius:999px;
  padding:.4rem .9rem; font-family:var(--font-display); font-weight:800; color:#7a4e0d;
  box-shadow:var(--shadow-pop), inset 0 1px 0 rgba(255,255,255,.6);
}
.coin-pill:hover{ transform:translateY(-1px); }
.coin-icon{ font-size:1.1rem; }

.top-actions{ margin-left:auto; display:flex; gap:.55rem; align-items:center; }

/* ---------- 4. ROOM / STAGE -------------------------------------------- */
.stage{
  position:absolute; inset:64px 0 92px 0;
  display:flex; align-items:center; justify-content:center;
  padding:1.2rem;
}
.room{
  position:relative;
  width:min(100%, 1200px);
  aspect-ratio:1600 / 1000;
  border-radius:var(--radius-lg);
  overflow:hidden;
  box-shadow:var(--shadow-soft), 0 0 0 2px var(--gold-edge);
  border:8px solid var(--gold);
  outline:3px solid var(--gold-dark);
  outline-offset:-13px;
  background:var(--purple-900);
}
.room-bg{
  position:absolute; inset:0; width:100%; height:100%;
  object-fit:cover; pointer-events:none; user-select:none;
}
.item-layer{ position:absolute; inset:0; }

.room-arrow{
  position:absolute; top:50%; transform:translateY(-50%);
  z-index:45;
  width:44px; height:44px; border-radius:50%;
  border:2px solid var(--gold);
  background:linear-gradient(180deg, var(--purple-700), var(--purple-900)); color:var(--gold-light);
  font-size:1.25rem; font-weight:800; line-height:1;
  display:flex; align-items:center; justify-content:center;
  box-shadow:var(--shadow-pop); touch-action:manipulation;
  user-select:none; -webkit-user-select:none;
}
.room-arrow:hover{ filter:brightness(1.15); }
.room-arrow:active{ transform:translateY(-50%) scale(.94); }
.room-prev{ left:6px; }
.room-next{ right:6px; }

.room-label{
  position:absolute; top:10px; left:50%; transform:translateX(-50%);
  z-index:45;
  font-family:var(--font-display);
  background:linear-gradient(180deg, var(--purple-600), var(--purple-800));
  color:var(--gold-light);
  border:2px solid var(--gold);
  border-radius:999px; padding:.35rem 1.1rem;
  font-weight:700; font-size:.95rem; white-space:nowrap;
  box-shadow:var(--shadow-pop); pointer-events:none;
  text-transform:capitalize;
}

/* ---------- 5. ITEMS (broken + placed) --------------------------------- */
.room-item{
  position:absolute;
  background-size:contain;
  background-repeat:no-repeat;
  background-position:center;
  touch-action:none;
}
.room-item.broken{ pointer-events:none; filter:drop-shadow(0 6px 10px rgba(0,0,0,.35)); }
.room-item.broken img{ width:100%; height:100%; object-fit:contain; display:block; }

.room-item.placed{
  cursor:grab;
  filter:drop-shadow(0 8px 14px rgba(0,0,0,.4));
}
.room-item.placed img{ width:100%; height:100%; object-fit:contain; display:block; pointer-events:none; }
.room-item.placed.dragging{ cursor:grabbing; z-index:2147483000; }
.room-item.placed.selected{ outline:3px dashed var(--gold); outline-offset:4px; border-radius:8px; }

.item-toolbar{
  position:absolute; top:-40px; left:50%; transform:translateX(-50%);
  display:flex; gap:.3rem; background:linear-gradient(180deg,#fff8ea,var(--cream)); border:2px solid var(--gold-dark); border-radius:999px; padding:.25rem;
  box-shadow:var(--shadow-pop); white-space:nowrap;
}
.item-toolbar button{
  border:none; background:var(--lilac-200); color:var(--purple-700);
  border-radius:999px; width:30px; height:30px; font-size:.85rem;
  touch-action:manipulation;
}
.item-toolbar button:hover{ background:var(--purple-500); color:#fff; }

.resize-handle{
  position:absolute; right:-10px; bottom:-10px; width:22px; height:22px;
  border-radius:50%; background:var(--gold); border:3px solid var(--gold-dark);
  box-shadow:var(--shadow-pop); cursor:nwse-resize;
}

/* ---------- 6. BOTTOM BAR ---------------------------------------------- */
.bottombar{
  position:absolute; bottom:0; left:0; right:0; height:92px; z-index:40;
  display:flex; align-items:center; justify-content:space-between;
  padding:0 1.4rem;
  background:linear-gradient(0deg, rgba(44,24,86,0.92), rgba(60,33,112,0.7));
  border-top:2px solid var(--gold);
}
.bottombar .btn-round span{ font-size:.95rem; }
#inventoryBtn{ background:linear-gradient(180deg,#efe3ff,#ddc9fb); color:var(--purple-800); border-color:rgba(255,255,255,.4); }

/* ---------- 7. MODALS ---------------------------------------------------*/
.modal-backdrop{
  position:absolute; inset:0; background:rgba(18,9,38,0.62);
  display:flex; align-items:center; justify-content:center; z-index:100;
  padding:1.2rem;
}
.modal{
  width:min(680px, 100%); max-height:82%; display:flex; flex-direction:column;
  background:
    radial-gradient(ellipse at top, rgba(255,255,255,.35), transparent 60%),
    linear-gradient(180deg, var(--cream), var(--parchment-dark));
  border-radius:var(--radius-lg); overflow:hidden;
  border:5px solid var(--gold);
  box-shadow:0 26px 60px rgba(10,4,26,0.55), inset 0 0 0 2px var(--gold-edge);
  animation:pop-in .18s ease;
}
.modal-small{ width:min(420px, 100%); }
@keyframes pop-in{ from{ transform:scale(.94); opacity:0;} to{ transform:scale(1); opacity:1;} }

.modal-header{
  display:flex; align-items:center; justify-content:space-between;
  padding:.85rem 1.3rem; margin:.85rem 1.3rem 0;
  background:linear-gradient(180deg, var(--purple-500), var(--purple-700));
  border:2px solid var(--gold);
  border-radius:999px;
  box-shadow:0 6px 14px rgba(20,8,44,.35), inset 0 1px 0 rgba(255,255,255,.25);
}
.modal-header h2{
  margin:0; font-family:var(--font-display); font-weight:700; font-size:1.15rem;
  color:#fff; text-shadow:0 2px 3px rgba(0,0,0,.35); text-align:center; width:100%;
}
.modal-close{
  border:2px solid var(--gold-dark); background:linear-gradient(180deg,#fff8ea,var(--cream));
  border-radius:50%; width:32px; height:32px;
  font-size:1rem; color:var(--purple-700); box-shadow:var(--shadow-pop);
  flex:0 0 auto;
}
.modal-body{
  padding:1.2rem 1.4rem 1.5rem; overflow-y:auto;
  overscroll-behavior:contain; -webkit-overflow-scrolling:touch;
  font-family:var(--font-body); color:var(--ink-strong);
}

/* ---------- 8. SHOP ------------------------------------------------------*/
.shop-category{
  background:linear-gradient(180deg,#fffaef,#fff2d2);
  border:2px solid var(--gold-dark);
  border-radius:var(--radius-md); padding:1rem;
  margin-bottom:1rem; box-shadow:0 3px 10px rgba(60,42,99,0.15);
}
.shop-category-title{
  font-family:var(--font-display);
  font-weight:700; color:var(--purple-800); letter-spacing:.03em;
  margin:0 0 .7rem; text-transform:uppercase; font-size:.95rem;
  display:flex; align-items:center; gap:.5rem;
}
.broken-remove-row{
  display:flex; align-items:center; gap:.7rem;
  background:var(--lilac-200); border:1px solid rgba(90,70,150,0.2); border-radius:var(--radius-sm);
  padding:.6rem .8rem; margin-bottom:.7rem;
}
.broken-remove-row img{ width:44px; height:44px; object-fit:contain; }
.broken-remove-row .grow{ flex:1; }
.broken-remove-row .title{ font-weight:700; font-size:.88rem; }
.broken-remove-row .sub{ font-size:.78rem; color:var(--muted); }

.tier-grid{ display:grid; grid-template-columns:repeat(auto-fill, minmax(140px,1fr)); gap:.7rem; }
.tier-card{
  background:linear-gradient(180deg,#fffdf6,var(--cream)); border:2px solid var(--gold-dark);
  border-radius:var(--radius-sm); padding:.6rem; text-align:center;
  display:flex; flex-direction:column; gap:.35rem;
  box-shadow:0 3px 8px rgba(60,42,99,.1);
}
.tier-card img{ width:100%; height:78px; object-fit:contain; }
.tier-card .tier-name{ font-family:var(--font-display); font-weight:700; font-size:.78rem; text-transform:uppercase; }
.tier-card.tier-cheap .tier-name{ color:#8a7452; }
.tier-card.tier-modern .tier-name{ color:#3f5f8a; }
.tier-card.tier-expensive .tier-name{ color:#b8860b; }
.tier-card.tier-Accessories .tier-name{ color:#9a5cb0; }
.tier-card .price{ font-weight:700; font-size:.82rem; color:var(--gold-dark); }
.tier-card .buy-btn{ font-size:.78rem; padding:.4rem .6rem; }
.tier-card .owned-tag{
  font-size:.72rem; font-weight:800; color:var(--green);
  background:#e4f7ef; border-radius:999px; padding:.25rem .5rem;
}

/* Flat-priced "Accessories" rows — one row per image, all the same price */
.accessory-row{
  display:flex; align-items:center; gap:.8rem;
  background:linear-gradient(180deg,#fffdf6,var(--cream)); border:2px solid var(--gold-dark);
  border-radius:var(--radius-sm); padding:.5rem .7rem; margin-bottom:.55rem;
}
.accessory-row img{ width:48px; height:48px; object-fit:contain; }
.accessory-row .grow{ flex:1; }
.accessory-row .title{ font-weight:800; font-size:.9rem; }
.accessory-row .sub{ font-size:.75rem; color:var(--muted); text-transform:capitalize; }
.accessory-row .owned-tag{ white-space:nowrap; }

/* ---------- 9. INVENTORY --------------------------------------------------*/
.inventory-empty{ text-align:center; color:var(--muted); padding:2rem 0; }
.inventory-row{
  display:flex; align-items:center; gap:.9rem;
  background:linear-gradient(180deg,#fffdf6,var(--cream)); border:2px solid var(--gold-dark);
  border-radius:var(--radius-md); padding:.7rem .9rem; margin-bottom:.6rem;
  box-shadow:0 3px 10px rgba(60,42,99,0.12);
}
.inventory-row img{ width:56px; height:56px; object-fit:contain; }
.inventory-row .grow{ flex:1; }
.inventory-row .title{ font-weight:800; font-size:.9rem; }
.inventory-row .sub{ font-size:.78rem; color:var(--muted); text-transform:capitalize; }

/* ---------- 10. TOAST ------------------------------------------------------*/
.toast{
  position:absolute; bottom:110px; left:50%; transform:translateX(-50%);
  background:linear-gradient(180deg, var(--purple-600), var(--purple-900));
  border:2px solid var(--gold);
  color:var(--gold-light); padding:.7rem 1.2rem; border-radius:999px;
  font-family:var(--font-display);
  font-size:.88rem; font-weight:700; box-shadow:var(--shadow-soft); z-index:200;
  animation:toast-in .18s ease;
}
.toast.error{ background:linear-gradient(180deg,#ef7a72,var(--red)); border-color:#fff; color:#fff; }
.toast.success{ background:linear-gradient(180deg,#7ed6ae,var(--green)); border-color:#fff; color:#fff; }
@keyframes toast-in{ from{ opacity:0; transform:translate(-50%,10px);} to{ opacity:1; transform:translate(-50%,0);} }

/* ---------- 12. SCREEN CONTROLS ("Экран" panel) ----------------------------*/
.screen-fab{
  position:absolute; right:22px; bottom:120px; z-index:75;
  display:flex; align-items:center; gap:.4rem;
  background:linear-gradient(180deg, var(--purple-700), var(--purple-950)); color:var(--gold-light); border:2px solid var(--gold);
  padding:.55rem 1rem; border-radius:999px; font-family:var(--font-display); font-weight:700; font-size:.85rem;
  box-shadow:var(--shadow-pop); touch-action:manipulation;
  user-select:none; -webkit-user-select:none;
}
.screen-fab:hover{ filter:brightness(1.12); }
.screen-fab:active{ transform:scale(.97); }

.screen-panel{
  position:absolute; right:22px; bottom:176px; z-index:76;
  display:flex; flex-direction:column; gap:.5rem; align-items:stretch;
  background:linear-gradient(180deg, var(--purple-800), var(--purple-950)); border:2px solid var(--gold);
  border-radius:18px; padding:.8rem; min-width:190px;
  box-shadow:-6px 12px 30px rgba(0,0,0,.5);
}
.screen-panel .sc-btn{
  border:1px solid var(--gold-dark); border-radius:999px; padding:.6rem .9rem; font-family:var(--font-display); font-weight:700;
  font-size:.85rem; background:linear-gradient(180deg, var(--purple-600), var(--purple-800)); color:var(--gold-light);
  touch-action:manipulation; text-align:center; user-select:none; -webkit-user-select:none;
}
.screen-panel .sc-btn:hover{ filter:brightness(1.2); }
.screen-panel .sc-btn:active{ transform:scale(.97); }
.screen-zoom{ display:flex; gap:.4rem; }
.screen-zoom .sc-btn{ flex:1; font-size:1rem; padding:.5rem .5rem; }
.screen-zoom .w-100{ font-size:.78rem; }

/* ---------- 13. ROTATION HINT ----------------------------------------------*/
.rotate-hint{
  position:absolute; bottom:128px; left:50%; transform:translateX(-50%);
  z-index:85; display:flex; align-items:center; gap:.6rem; max-width:92%;
  background:linear-gradient(180deg, var(--purple-800), var(--purple-950)); border:2px solid var(--gold); color:var(--gold-light);
  padding:.55rem 1rem; border-radius:999px; font-size:.85rem;
  box-shadow:var(--shadow-pop);
}
.rotate-hint button{
  border:none; background:rgba(255,255,255,.15); color:#fff;
  width:24px; height:24px; border-radius:50%; font-size:.7rem; line-height:1;
  flex:0 0 auto; touch-action:manipulation;
}

/* ---------- 14. COIN EDITOR --------------------------------------------------*/
.coin-editor-row{ display:flex; gap:.5rem; margin-bottom:.7rem; }
.coin-editor-row input{
  flex:1; border:2px solid var(--gold-dark); border-radius:999px;
  padding:.5rem .9rem; font-size:.9rem; background:#fffdf6; color:var(--ink-strong);
}

/* ---------- 15. RESPONSIVE -----------------------------------------------------*/
@media (max-width: 640px){
  .brand{ display:none; }
  .top-actions{ gap:.35rem; }
  .btn{ padding:.55rem .75rem; font-size:.8rem; }
  .bottombar .btn-round span{ display:none; }
}

/* ---------- 16. START MENU -----------------------------------------------------*/
.start-overlay{
  position:absolute; inset:0; z-index:95;
  display:flex; align-items:center; justify-content:center;
  background:
    radial-gradient(ellipse 120% 70% at 50% -10%, #6a3fb0 0%, transparent 55%),
    rgba(18,9,38,0.7);
  backdrop-filter:blur(3px);
  padding:1.2rem;
  animation:pop-in .18s ease;
}
.start-card{
  width:min(400px, 100%);
  background:
    radial-gradient(ellipse at top, rgba(255,255,255,.35), transparent 60%),
    linear-gradient(180deg, var(--cream), var(--parchment-dark));
  border-radius:var(--radius-lg);
  border:5px solid var(--gold);
  padding:1.9rem 1.6rem 1.6rem;
  text-align:center;
  box-shadow:0 26px 60px rgba(10,4,26,0.55), inset 0 0 0 2px var(--gold-edge);
  animation:pop-in .18s ease;
}
.start-title{
  margin:0 0 .3rem; font-family:var(--font-display); font-weight:800; font-size:1.6rem; color:var(--purple-800);
}
.start-sub{ margin:0 0 1.1rem; }
.start-card .btn-block{ margin-top:.65rem; }
.how-line{ margin:0 0 .85rem; font-family:var(--font-body); }

/* ---------- 18. DEMO LOCKED SHOP (subscription) --------------------------- */
/* Only "Repairs" is buyable. All furniture/accessory categories are shown
   black & white and locked behind the subscription prompt. */
.shop-category.locked .tier-card img,
.shop-category.locked .accessory-row img{
  filter:grayscale(1); opacity:.6;
}
.shop-category.locked .tier-name{ color:var(--muted); }
.shop-category.locked .price{ color:var(--muted); }
.shop-category.locked .sub{ color:var(--muted); }
.locked-tag{ font-size:.9rem; }
.unlock-btn{ margin-left:auto; font-size:.78rem; padding:.4rem .7rem; white-space:nowrap; }

/* Subscription prompt modal */
.subscribe-body{ text-align:center; }
.subscribe-body .how-line{ margin-bottom:1.2rem; font-size:1rem; }
.subscribe-body .btn{ text-decoration:none; }
